﻿#include "servicecenter.h"
#include "servermonitorcenter.h"
#include "serverinfopushcenter.h"

#include <QCoreApplication>
#include <qglobalconfig.h>
#include <servermonitorcontroller.h>
#include <tcpsocketnetworkcenter.h>
#include <udpsocketnetworkcenter.h>
#include <websocketnetworkcenter.h>

ServiceCenter::ServiceCenter(QObject *parent) : QObject(parent)
{
    qDebug() << __FUNCTION__;
    QGlobalConfig::getInstance().init(QCoreApplication::applicationDirPath() + "/config.ini");
    ServerMonitorCenter::getInstance();

    bool httpNetWorkOpen = QGlobalConfig::getInstance().read("netWork","httpNetWorkOpen",true).toBool();
    bool tcpSocketOpen = QGlobalConfig::getInstance().read("netWork","tcpSocketOpen",true).toBool();
    bool udpSocketOpen = QGlobalConfig::getInstance().read("netWork","udpSocketOpen",true).toBool();
    bool webSocketOpen = QGlobalConfig::getInstance().read("netWork","webSocketOpen",true).toBool();

    if(httpNetWorkOpen){
        HttpService::getInstance();
        //安装 服务监控 控制器
        HttpService::getInstance().installController("resourcemonitor", new ServerMonitorController(this));
    }
    if(tcpSocketOpen){
        TcpSocketNetWorkCenter::getInstance();
    }
    if(udpSocketOpen){
        UdpSocketNetWorkCenter::getInstance();
    }
    if(webSocketOpen){
        WebSocketNetWorkCenter::getInstance();
    }

    //启动推送线程
    ServerInfoPushCenter::getInstance();
}


ServiceCenter::~ServiceCenter()
{
    TcpSocketNetWorkCenter::deleteInstance();
    UdpSocketNetWorkCenter::deleteInstance();
    WebSocketNetWorkCenter::deleteInstance();
    ServerMonitorCenter::deleteInstance();
    QGlobalConfig::deleteInstance();
}
